//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Globalization;
using System.Windows.Data;

namespace OpenLS.Spreadsheet.UI
{
    internal class BorderThicknessConverter : IValueConverter //\\duplicate 
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return 0;
            Borders b = (Borders) value;
            if (targetType == typeof (double))
            {
                switch (parameter.ToString())
                {
                    case "left":
                        return StyleToThickness(b.Left);
                    case "right":
                        return StyleToThickness(b.Right);
                    case "top":
                        return StyleToThickness(b.Top);
                    case "bottom":
                        return StyleToThickness(b.Bottom);
                }
            }
            throw new NotImplementedException();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion

        private static double StyleToThickness(Border item)
        {
            if (item == null)
                return 0;
            return BorderStyleToThicknessConverter.StyleToThickness(item.Style);
        }
    }
}